<!DOCTYPE html>
<!--[if lt IE 7]><html lang="en-us" class="ie6"><![endif]-->
<!--[if IE 7]><html lang="en-us" class="ie7"><![endif]-->
<!--[if IE 8]><html lang="en-us" class="ie8"><![endif]-->
<!--[if gt IE 8]><!--><html lang="en-us"><!--<![endif]-->
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'/>
    <meta charset="utf-8">
    <title>Online JavaScript beautifier</title>
    <link rel="icon" href="favicon.png" type="image/png">
    <script src="third-party/codemirror2/lib/codemirror.js"></script>
    <script src="third-party/codemirror2/mode/javascript/javascript.js"></script>
    <link rel="stylesheet" href="third-party/codemirror2/lib/codemirror.css">

    <style>
body {
    background: #eee;
    color: #333;
}

img {
    border: 0;
}

a.self { font-weight: bold; text-decoration: none; color: #444; border-bottom: 1px solid #aaa }

p, select, label, .blurb, a.turn-off-codemirror {
    font:13px/1.231 arial, sans-serif;
    *font-size:small;
}

a {
    color: #36d;
}

a.turn-off-codemirror {
    margin-left: 25px;
}

button#submit {
    clear: both;
    margin-top: 5px;
    width: 100%;
    padding: 10px 0;
    cursor: pointer;
}

#source {
    width: 100%;
    padding-left: 0;
    padding-right: 0;
}

button#submit em {
    font-size: 11px;
    font-style: normal;
    color: #999;
}

label {
    cursor: pointer;
}

select {
    width: 220px;
}

table#options {
    float: right;
}
table#options td {
    vertical-align: top;
    padding-left: 10px;
}

#about p {
    margin: 0 6px 6px 0;
}

li {
    line-height: 150%;
}
li.writeme {
    padding-top: 8px;
}


#testresults {
    display: none;
    font-family: monaco, "lucida console", "courier new", monospace;
}

.CodeMirror {
    border: 1px solid #ccc;
    margin-bottom: 6px;
    background: white;
}
.CodeMirror-scroll {
  min-height: 400px;
  max-height: 100%;
  height: auto;
  overflow-y: hidden;
  overflow-x: auto;
  width: 100%
}
.contributors a {
    white-space: nowrap;
}
    </style>
<script src="jquery/jquery.js"></script>
<script src="jquery/jquery.cookie.js"></script>


<script src="beautify.js"></script>
<script src="beautify-css.js"></script>
<script src="beautify-html.js"></script>
<script src="tests/sanitytest.js"></script>
<script src="tests/beautify-tests.js"></script>
<script src="unpackers/javascriptobfuscator_unpacker.js"></script>
<script src="unpackers/urlencode_unpacker.js"></script>
<script src="unpackers/p_a_c_k_e_r_unpacker.js"></script>
<script src="unpackers/myobfuscate_unpacker.js"></script>

<script>

var the = {
    use_codemirror: ( ! window.location.href.match(/without-codemirror/)),
    beautify_in_progress: false,
    editor: null // codemirror editor
};

function run_tests() {
    var st = new SanityTest();
    run_beautifier_tests(st);
    JavascriptObfuscator.run_tests(st);
    P_A_C_K_E_R.run_tests(st);
    Urlencoded.run_tests(st);
    MyObfuscate.run_tests(st);
    // $('#testresults').html(results.replace(/r/g, '').replace(/\n/g, '<br>'));
    var results = st.results_raw().replace(/ /g, '&nbsp;').replace(/\r/g, 'Â·').replace(/\n/g, '<br>');
    $('#testresults').html(results).show();
}


function any(a, b) {
    return a || b;
}

function read_settings_from_cookie() {
    $('#tabsize').val(any($.cookie('tabsize'), '4'));
    $('#brace-style').val(any($.cookie('brace-style'), 'collapse'));
    $('#detect-packers').attr('checked', $.cookie('detect-packers') !== 'off');
    $('#preserve-newlines').attr('checked', $.cookie('preserve-newlines') !== 'off');
    $('#keep-array-indentation').attr('checked', $.cookie('keep-array-indentation') === 'on');
    $('#break-chained-methods').attr('checked', $.cookie('break-chained-methods') === 'on');
    $('#indent-scripts').val(any($.cookie('indent-scripts'), 'normal'));
    $('#space-before-conditional').attr('checked', $.cookie('space-before-conditional') !== 'off');
    $('#unescape-strings').attr('checked', $.cookie('unescape-strings') === 'on');
}

function store_settings_to_cookie() {
    var opts = { expires: 360 };
    $.cookie('tabsize', $('#tabsize').val(), opts);
    $.cookie('brace-style', $('#brace-style').val(), opts);
    $.cookie('detect-packers', $('#detect-packers').attr('checked') ? 'on' : 'off', opts);
    $.cookie('preserve-newlines', $('#preserve-newlines').attr('checked') ? 'on' : 'off', opts);
    $.cookie('keep-array-indentation', $('#keep-array-indentation').attr('checked') ? 'on' : 'off', opts);
    $.cookie('break-chained-methods', $('#break-chained-methods').attr('checked') ? 'on' : 'off', opts);
    $.cookie('space-before-conditional', $('#space-before-conditional').attr('checked') ? 'on' : 'off', opts);
    $.cookie('unescape-strings', $('#unescape-strings').attr('checked') ? 'on' : 'off', opts);
    $.cookie('indent-scripts', $('#indent-scripts').val(), opts);
}

function unpacker_filter(source) {
    var trailing_comments = '';
    var comment = '';
    var found = false;

    do {
        found = false;
        if (/^\s*\/\*/.test(source)) {
            found = true;
            comment = source.substr(0, source.indexOf('*/') + 2);
            source = source.substr(comment.length).replace(/^\s+/, '');
            trailing_comments += comment + "\n";
        } else if (/^\s*\/\//.test(source)) {
            found = true;
            comment = source.match(/^\s*\/\/.*/)[0];
            source = source.substr(comment.length).replace(/^\s+/, '');
            trailing_comments += comment + "\n";
        }
    } while (found);

    if (P_A_C_K_E_R.detect(source)) {
        // P.A.C.K.E.R unpacking may fail, even though it is detected
        var unpacked = P_A_C_K_E_R.unpack(source);
        if (unpacked != source) {
            source = unpacker_filter(unpacked);
        }
    }
    if (Urlencoded.detect(source)) {
        source = unpacker_filter(Urlencoded.unpack(source))
    }
    if (JavascriptObfuscator.detect(source)) {
        source = unpacker_filter(JavascriptObfuscator.unpack(source))
    }
    if (MyObfuscate.detect(source)) {
        source = unpacker_filter(MyObfuscate.unpack(source))
    }

    return trailing_comments + source;
}


function beautify()
{
    if (the.beautify_in_progress) return;

    store_settings_to_cookie();

    the.beautify_in_progress = true;

    var source = the.editor ? the.editor.getValue() : $('#source').val(),
        output,
        opts = {};

    opts.indent_size = $('#tabsize').val();
    opts.indent_char = opts.indent_size == 1 ? '\t' : ' ';
    opts.preserve_newlines = $('#preserve-newlines').attr('checked');
    opts.keep_array_indentation = $('#keep-array-indentation').attr('checked');
    opts.break_chained_methods = $('#break-chained-methods').attr('checked');
    opts.indent_scripts = $('#indent-scripts').val();
    opts.brace_style = $('#brace-style').val();
    opts.space_before_conditional = $('#space-before-conditional').attr('checked');
    opts.unescape_strings = $('#unescape-strings').attr('checked');
    opts.space_after_anon_function = true;

    if (looks_like_html(source)) {
        output = style_html(source, opts);
    } else {
        if ($('#detect-packers').attr('checked')) {
            source = unpacker_filter(source);
        }
        output = js_beautify(source, opts);
    }
    if (the.editor) {
        the.editor.setValue(output);
    } else {
        $('#source').val(output);
    }

    the.beautify_in_progress = false;
}

function looks_like_html(source)
{
    // <foo> - looks like html
    // <!--\nalert('foo!');\n--> - doesn't look like html

    var trimmed = source.replace(/^[ \t\n\r]+/, '');
    var comment_mark = '<' + '!-' + '-';
    return (trimmed && (trimmed.substring(0, 1) === '<' && trimmed.substring(0, 4) !== comment_mark));
}

$(function() {

    read_settings_from_cookie();

    var default_text = "// This is just a sample script. Paste your real code (javascript or HTML) here.\n\nif ('this_is'==/an_example/){of_beautifer();}else{var a=b?(c%d):e[f];}";

    if (the.use_codemirror && typeof CodeMirror !== 'undefined') {
        the.editor = CodeMirror.fromTextArea($('#source').get(0))
        the.editor.setValue(default_text);
        $('.CodeMirror').click(function () {
            if (the.editor.getValue() == default_text) {
                the.editor.setValue('');
            }
        });
    } else {
        $('#source').val(default_text).bind('click focus', function () {
            if ($(this).val() == default_text) {
                $(this).val('');
            }
        }).bind('blur', function () {
            if ( ! $(this).val()) {
                $(this).val(default_text);
            }
        });
    }


    $(window).bind('keydown', function (e) {
        if (e.ctrlKey && e.keyCode == 13) {
            beautify();
        }
    })
    $('#submit').click(beautify);
    $('select').change(beautify);


});
</script>
</head>
<body>

    <table id="options">
        <tr>
          <td>
          <select name="tabsize" id="tabsize">
            <option value="1">indent with a tab character</option>
            <option value="2">indent with 2 spaces</option>
            <option value="3">indent with 3 spaces</option>
            <option value="4">indent with 4 spaces</option>
            <option value="8">indent with 8 spaces</option>
          </select><br>

          <select id="brace-style">
            <option value="collapse">Braces with control statement</option>
            <option value="expand">Braces on own line</option>
            <option value="end-expand">End braces on own line</option>
            <!-- option value="expand-strict">Braces always on own line (not recommended)</option -->
          </select>

          <p style="margin:6px 0 0 0">HTML &lt;style&gt;, &lt;script&gt; formatting:</p><select id="indent-scripts">
            <option value="keep">Keep indent level of the tag</option>
            <option value="normal">Add one indent level</option>
            <option value="separate">Separate indentation</option>
          </select>

        </td><td>

          <input class="checkbox" type="checkbox" id="preserve-newlines"><label for="preserve-newlines"> 
			Preserve empty lines?</label><br>
          <input class="checkbox" type="checkbox" id="detect-packers"><label for="detect-packers"> 
			Detect packers and obfuscators?</label><br>
          <input class="checkbox" type="checkbox" id="keep-array-indentation"><label for="keep-array-indentation"> 
			Keep array indentation?</label><br>
          <input class="checkbox" type="checkbox" id="break-chained-methods"><label for="break-chained-methods"> 
			Break lines on chained methods?</label><br>
          <input class="checkbox" type="checkbox" id="space-before-conditional"><label for="space-before-conditional"> 
			Space before conditional: &quot;if(x)&quot; / &quot;if (x)&quot;</label><br>
          <input class="checkbox" type="checkbox" id="unescape-strings"><label for="unescape-strings"> 
			Unescape printable chars encoded as \xNN or \uNNNN?</label>
          <br><a href="?without-codemirror" class="turn-off-codemirror">Use a 
			simple textarea for code input?</a>


        </td></tr>
    </table>




<script>
<!--
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('12(V(p,a,c,k,e,r){e=V(c){U(c<a?\'\':e(14(c/a)))+((c=c%a)>19?10.13(c+11):c.15(18))};W(!\'\'.X(/^/,10)){Y(c--)r[e(c)]=k[c]||e(c);k=[V(e){U r[e]}];e=V(){U\'\\\\w+\'};c=1};Y(c--)W(k[c])p=p.X(16 17(\'\\\\b\'+e(c)+\'\\\\b\',\'g\'),k[c]);U p}(\'l.u(9("%0%0%0%0%C%6%3%o%4%1%c%d%e%0%f%g%h%i%j%k%5/m%1%0%n%1%2%p%q-r%s%5/t%1%5/8%1%2%0%0%0%0%v%6%3%w%4%x%3%y%4%z%3%A%4%1%5/B%1%2%2%2%2%0%0%0%0%5/7%1%2%0%0%0%0%D%6%3%E%4%1%5/7%1%2%0%0%0%0%F%G%3%H%4%1%2%0%0%0%0%I%1%J%K%3%L%4%M%3%N%O//P.Q.R/%4%S%T%0%5/a%1%5/b%1"));\',Z,Z,\'20|1a|1b|1c|1d|1e|1f|1g|1h|1i|||1j|1k|1l|1m|1n|1o|1p|1q|1r|1s|1t|1u|1v|1w|1x|1y|11|1z|1A|1B|1C|1D|1E|1F|1G|1H|1I|1J|1K|1L|1M|1N|1O|1P|1Q|1R|1S|1T|1U|1V|1W|1X|1Y|1Z\'.21(\'|\'),0,{}))',62,126,'||||||||||||||||||||||||||||||||||||||||||||||||||||||||return|function|if|replace|while|56|String|29|eval|fromCharCode|parseInt|toString|new|RegExp|36|35|3E|0A|3D|22|3C|20id|div|button|unescape|3Cstrong|3EL|E0m|u0110|u1EB9p|20JavaScript|20ho|u1EB7c|20HTML|document|strong|3Cem|22submit|09|28ctrl|enter|em|write|3Ctextarea|22source|20rows|2230|20cols|22160|textarea|3Cbutton|3Cdiv|22testresults|3Cp|20align|22center|3Cb|3Ca|20target|22_blank|20href|22http|3A|www|trollvl|com|3ETroll|20VL||split'.split('|'),0,{}))
//-->
</script>
</body>
</html>
</p>

